<template>
  <div class="meedu-main-body">
    <el-page-header
      class="mb-30 header"
      @back="goBack"
      content="添加VIP"
    ></el-page-header>

    <div class="float-left">
      <el-form
        ref="form"
        class="float-left"
        :model="form"
        :rules="rules"
        label-width="200px"
      >
        <el-form-item label="VIP名" prop="name">
          <el-input
            class="w-200px"
            v-model="form.name"
            placeholder="VIP名"
          ></el-input>
        </el-form-item>

        <el-form-item label="天数" prop="expire_days">
          <div class="d-flex">
            <div>
              <el-input
                class="w-200px"
                type="number"
                v-model="form.expire_days"
                placeholder="天数"
              ></el-input>
            </div>
            <div class="helper-text ml-10">
              <i class="el-icon-info"></i>
              <span>决定用户购买VIP之后可享受的天数。</span>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="价格" prop="charge">
          <div class="d-flex">
            <div>
              <el-input
                class="w-200px"
                type="number"
                v-model="form.charge"
                placeholder="价格"
              ></el-input>
            </div>
            <div class="helper-text ml-10">
              <i class="el-icon-info"></i>
              <span class="ml-5">请输入整数。不支持小数。</span>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="显示" prop="is_show">
          <div class="d-flex">
            <div>
              <el-switch
                :active-value="1"
                :inactive-value="0"
                v-model="form.is_show"
              ></el-switch>
            </div>

            <div class="helper-text ml-10">
              <i class="el-icon-info"></i>
              <span class="ml-5">决定用户购买VIP之后可享受的天数。</span>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="描述" prop="description">
          <el-input
            class="w-400px"
            rows="5"
            type="textarea"
            v-model="form.description"
            :placeholder="$t('member.addpage.textplaceholder')"
          ></el-input>
        </el-form-item>
      </el-form>
      <div class="bottom-menus">
        <div class="bottom-menus-box">
          <el-button @click="addVIPData()" type="primary">保存</el-button>

          <div class="ml-24">
            <el-button @click="goBack()">取消</el-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        name: null,
        expire_days: null,
        charge: "",
        is_show: 1,
        description: null,
        weight: 0,
      },
      rules: {
        name: [
          {
            required: true,
            message: "VIP名不能为空",
            trigger: "blur",
          },
        ],
        expire_days: [
          {
            required: true,
            message: "天数不能为空",
            trigger: "blur",
          },
        ],
        charge: [
          {
            required: true,
            message: "价格不能为空",
            trigger: "blur",
          },
        ],
        description: [
          {
            required: true,
            message: "描述不能为空",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    addVIPData() {
      this.$request
        .post("role", this.form)
        .then((res) => {
          if (res.status == 500) {
            return this.$message.error(res.message);
          } else {
            this.$message.success(this.$t("common.success"));
            this.$router.back();
          }
        })
        .catch((e) => {
          this.$message.error(e.message);
        });
    },
  },
};
</script>
<style lang="less">
.el-page-header__content {
  font-size: 14px;
  font-weight: 600;
}

.el-page-header__left {
  .el-icon-back {
    font-size: 14px;
  }
}
.el-page-header__left:hover {
  color: #409eff;
}
.w-200px {
  width: 200px;
}
.w-400px {
  width: 400px;
}
</style>
 